package org.finesys.ai.controller.chat;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.RequiredArgsConstructor;
import org.finesys.ai.core.chat.ChatCompletionResponse;
import org.finesys.ai.dto.ChatReq;
import org.finesys.ai.entity.AigcModel;
import org.finesys.ai.service.AigcChatService;
import org.finesys.common.core.module.R;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.List;

@RestController
@RequiredArgsConstructor
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class DeepseekController {

    private final AigcChatService aigcChatService;


    @GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE + ";charset=UTF-8")
    public Flux<ChatCompletionResponse> chatCompletion(String appId, String conversionId, String prompt) {
        ChatReq chatReq = new ChatReq();
        chatReq.setAppId(appId);
        chatReq.setConversationId(conversionId);
        chatReq.setPromptText(prompt);
        return aigcChatService.chatFluxCompletion(chatReq);
    }

    /**
     * 获取模型列表
     *
     * @return 包含模型信息的响应对象
     */
    @GetMapping("/models")
    public R<List<AigcModel>> models(String provider) {
        List<AigcModel> aigcModelList = aigcChatService.models(provider);
        if (aigcModelList != null && !aigcModelList.isEmpty()) {
            return R.success(aigcChatService.models(provider));
        }
        return R.failed("模型列表为空");
    }
}
